﻿package com.czkj.hwz.decorate.Activity;

import android.content.Intent;
import android.os.Build;
import android.util.Log;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.czkj.hwz.decorate.R;
import com.czkj.hwz.decorate.base.HttpUrl;
import com.czkj.hwz.decorate.base.TabEntity;
import com.czkj.hwz.decorate.bean.Goods;
import com.flyco.tablayout.CommonTabLayout;
import com.flyco.tablayout.listener.CustomTabEntity;
import com.flyco.tablayout.listener.OnTabSelectListener;
import com.king.base.BaseActivity;
import com.king.base.util.ToastUtils;

import net.tsz.afinal.FinalBitmap;

import java.util.ArrayList;

//黄维柱有点幼稚

//黄维柱让人难以想象的愚蠢

//黄维柱情商很低


public class DetailActivity extends BaseActivity {
    private static final String TAG = "DetailActivity";
    private CommonTabLayout tab_index;
    private LinearLayout marketing_center;
    private String mTitle;
    private ImageView iv;
    private TextView selfSupport,productInfo,price,construction_personnel_reward,recommender_reward,operation_center_name;

    private FinalBitmap fb;
    private Goods goods;
    private String[] mTitles = {"运营中心","购物车"};
    private ArrayList<CustomTabEntity> mTabEntities = new ArrayList<>();
    private int[] mIconUnselectIds = {
            R.drawable.operation_center_normal,
            R.mipmap.w_shop};
    private int[] mIconSelectIds = {
            R.drawable.operation_center_selected,
            R.mipmap.y_shop};

    @Override
    public void initUI() {
        if (Build.VERSION.SDK_INT >= 21){
            Window window = getWindow();
            //取消设置透明状态栏,使 ContentView 内容不再覆盖状态栏
            window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
            //需要设置这个 flag 才能调用 setStatusBarColor 来设置状态栏颜色
            window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
            //设置状态栏颜色
            window.setStatusBarColor(getResources().getColor(R.color.yellow));
        }
        setContentView(R.layout.activity_detail);
        getSupportActionBar().hide();
        tab_index=findView(R.id.tab_index);
        iv=findView(R.id.iv);
        productInfo=findView(R.id.product_info);
        selfSupport=findView(R.id.self_support);
        price=findView(R.id.price);
        construction_personnel_reward=findView(R.id.construction_personnel_reward);
        recommender_reward=findView(R.id.recommender_reward);
        operation_center_name=findView(R.id.operation_center_tv);
        for (int i=0;i<mTitles.length;i++) {
            mTabEntities.add(new TabEntity(mTitles[i],mIconSelectIds[i],mIconUnselectIds[i]));
        }
        ArrayList<Goods> mGoodsList= (ArrayList<Goods>) getIntent().getSerializableExtra("mGoodsList");
        int position=getIntent().getIntExtra("position",0);
        mTitle=getIntent().getStringExtra("mTitle");
        goods=mGoodsList.get(position);
        tab_index.setTabData(mTabEntities);
        tab_index.setOnTabSelectListener(new OnTabSelectListener() {
            @Override
            public void onTabSelect(int position) {
                Log.d(TAG, "onTabSelect: "+position);
            }

            @Override
            public void onTabReselect(int position) {

            }
        });
        if (fb==null) {
            fb=FinalBitmap.create(this);
            fb.configBitmapMaxHeight(150);
            fb.configBitmapMaxWidth(150);
        }
    }

    @Override
    public void initData() {
        fb.display(iv, HttpUrl.BASE_URL+goods.getBigImg());
        if (goods.isSelfSupport()) {
            selfSupport.setText("[自营]");
        }else {
            selfSupport.setText("[非自营]");
        }
        productInfo.setText(goods.getName());
        price.setText("￥"+goods.getPrice());
        construction_personnel_reward.setText(goods.getWorkerReward()+"%");
        recommender_reward.setText(goods.getReferenceReward()+"%");
        operation_center_name.setText(mTitle);
    }

    @Override
    public void addListeners() {

    }
    public void OnClick(View v) {
        switch (v.getId()) {
            case R.id.join_the_shoppingcart:
                ToastUtils.showToast(context,"123");
                break;
            case R.id.buy_immediately:
                ToastUtils.showToast(context,"124");
                break;
            case R.id.marketing_center:
                Intent intent=new Intent(context,CenterOperationActivity.class);
                startActivity(intent);
                break;
            case R.id.iv_back:
                finish();
                break;
        }
    }


}
